import React, { createContext } from "react";
import { Button, message } from "antd";

const NotifyApiContext = createContext()
const useNotify = () => {
  const [messageApi, contextHolder] = message.useMessage();

  function loading(content = "加载中", duration = 0) {
    messageApi.open({
      type: "loading",
      content: content,
      duration: duration,
    });
  }

  function success(content = "成功") {
    messageApi.open({
        type: 'success',
        content: content,
    });
  }

  function warning(content){
    messageApi.open({
      type: 'warning',
      content: content,
    });
  };

  function error(content){
    messageApi.open({
      type: 'error',
      content: content,
    });
  };

  function destroy() {
    messageApi.destroy();
  }

  const notifyApi = {
    loading: loading,
    success: success,
    error: error,
    warning: warning,
    destroy: destroy
  }

  return [contextHolder, notifyApi]
};

export {useNotify, NotifyApiContext}
